const Label = require("../model/label.model");

const verifyLabelExists = async (ctx, next) => {
  const { name } = ctx.request.body;

  const result = await Label.findOne({
    where: { name },
  });
  if (result) {
    // const error = new Error(errorType.USER_ALREADY_EXISTS);
    // return ctx.app.emit("error", error, ctx);
    return ctx.fail(409, "标签名已存在");
  }
  await next();
};

module.exports = {
  verifyLabelExists,
};
